package cn.wolfcode.trip.app.web.controller;

import cn.wolfcode.trip.app.util.HttpUtil;
import cn.wolfcode.trip.base.query.HotelQueryObject;
import cn.wolfcode.trip.base.service.IHotelService;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.net.URLEncoder;

@RestController
@RequestMapping("/data")
public class DataController {
    /*
        查询新闻
        动作:GET
        资源:/hotels/{type}
        参数:
     */
    @GetMapping(value = "/news", produces = "text/html;charset=UTF-8")
    public Object getNews(String type) throws Exception {
        String content = HttpUtil.doGetRequest("http://v.juhe.cn/toutiao/index?key=4800205dbb354a31d21dd659b07a817b" + "&type=" + type);
        return JSON.toJSON(content);
    }

    @GetMapping(value = "/news1", produces = "text/html;charset=UTF-8")
    public Object getNews1(String type) throws Exception {
        String content = HttpUtil.doGetRequest("http://v.juhe.cn/toutiao/index?key=4800205dbb354a31d21dd659b07a817b" + "&type=" + type);
        return JSON.toJSON(content);
    }

    private String getChannel(){
        String url="https://way.jd.com/jisuapi/channel?appkey=ef58c40158c4108ba0f8fc459c554c16";

        return null;
    }
    /*
        查询天气
        动作:GET
        资源:/hotels/{type}
        参数:
     */
    @GetMapping(value = "/weather", produces = "text/html;charset=UTF-8")
    public Object getWeather(String city) throws Exception {
        city = URLEncoder.encode(city, "UTF-8");
        String content = HttpUtil.doGetRequest("http://apis.juhe.cn/simpleWeather/query?key=0ef3e474475c6efde010f3037df52d40" + "&city=" + city);
        return JSON.toJSON(content);
    }
}
